<?php
//Getting the headcategory from the location scroll post
//Else getting it from the headcategory link
$headCategory=$_POST['headCategory'];
if (isset($headCategory)==false) {$headCategory = (isset($_GET['headCategory']))?$_GET['headCategory']:0;}

//Same as above with subCategory, the reason for this is the conflict with the post-function
$subCategory=$_POST['subCategory'];
if (isset($subCategory)==false) { $subCategory = (isset($_GET['subCategory']))?$_GET['subCategory']:0;}

$priceSort=$_GET['priceSort'];

$location=$_GET['location'];

include '../Huvudmeny/index.php';
include '../SubMenu/subMenu.php';
echo '<br><br><br>';
include '../phpFunctions/picIndexArray.php';
include '../phpFunctions/getSinglePictureUrl.php';
    $i2 = 0;
     $top = 20;
     $left = 0;
     $marginLeft = 0;
     $marginTop = 0;
     $squaresPerRow = 4;
     $numberOfSquares = 20;
     $squareHeight = 205; //Don't forget to change height and width in the CSS file to
     $squareWidth = 181;
     $picIndex = itemIndexArray($headCategory, $location, $subCategory,$priceSort);
     $totalNumberOfItems = count($picIndex);
     $hooverColor ='"thin solid grey"';
     $standardColor  ='"thin solid white"';
     $url = '../Bildgalleri/showItem.php';




?>

<center>
   

    
              
            





    <div class="grid" >
<!--        Börjar med att infoga två bläddermanicker-->
                <div style="z-index: 100; position: absolute; right: -60px; top: -30px;  width: 200px; padding: 10px;  ">
                <?php include '../phpFunctions/previousNextFunction.php';?>
                </div>
                <div style="z-index: 100; position: absolute; right: 370px; top: 920px;  width: 200px; padding: 10px;  ">
                <?php include '../phpFunctions/previousNextFunction.php';?>
                </div>
<?php

     //Loop creates the grid and the objects inside it
        while($i2  <$numberOfSquares && $i2<$totalNumberOfItems ) {


            $picURL = getSinglePictureUrl($picIndex[$i2 + $currentPage]);//Adding currentPage beacause we want to show next window of items
            $itemPrice = getItemPrice($picIndex[$i2 + $currentPage]);
            $itemSize = getItemSize($picIndex[$i2 + $currentPage]);

            if ($marginLeft > $squaresPerRow) {$top = $top+$squareHeight;
                                              ++$marginTop;
                                              $left = 0;
                                              $marginLeft=0;
                                              }


            echo  "<a href='", $url, '?itemID=' . $picIndex[$i2 + $currentPage] .'&back=show'. "'>";
            ////Unique url for each Item, the itemID i sent to that url with the $_GET function and information about that specific item can be obtained from the database

            print "<div class='cell' style='top:$top";
            print "px; left: $left";
            print "px; margin-left: $marginLeft";
            print "px; margin-top: $marginTop";
            print "px;'";



//            print "background-image: url(../Bildgalleri/Paintings/$picURL)";
            print "onmouseover='this.style.border=$hooverColor;' onmouseout='this.style.border=$standardColor;'";

            print">";
            if ($picURL != NULL){
            print "<br><img src='../Bildgalleri/Paintings/$picURL' width='96' height='96'>
                   <br><p>Pris: $itemPrice kr</p>
                   <br><p>Storlek: $itemSize</p>";

            }
            print"</div></a>";



            ++$picIndex;
            ++$marginLeft;
            ++$i2;
            $left = $left +$squareWidth;

       }


    if ($headCategory == NULL){$showHeadCategory = "Alla";}
    else {$showHeadCategory = $headCategory; }

    if ($subCategory == NULL){$showSubcategory = "&nbsp;";}
       if ($subCategory != NULL){$showSubcategory = ",&nbsp;$subCategory";}
?>
                <div style=' position:absolute; top: 10px; left:395px;   width:104px; text-transform: uppercase;  font-size:12px; font-weight: bold; color:black; font-family:Helvetica, sans-serif;'><?php echo "$showHeadCategory$showSubcategory";?></div>
                <div>
                <?php include '../phpFunctions/locationScroll.php'; ?>
                <?php include '../phpFunctions/sortScroll.php'; ?>
                </div>
                

</div>


</center>

 
<?php include '../Banner/sidfot.php'; ?>
